Skip to content

feat: add missing SAFE_ERROR_CODES for rate limiting and auth errors#980

Merged
pyramation merged 2 commits intomainfrom
devin/1776247185-safe-error-codes
Apr 16, 2026
Merged

feat: add missing SAFE_ERROR_CODES for rate limiting and auth errors#980
pyramation merged 2 commits intomainfrom
devin/1776247185-safe-error-codes

Conversation

@pyramation
Copy link
Copy Markdown
Contributor

@pyramation pyramation commented Apr 15, 2026

Summary

Adds 11 new error codes to the SAFE_ERROR_CODES allowlist in the GraphQL middleware. Without this change, these database-raised errors are masked as generic "Internal Server Error" responses in production, preventing clients from handling them appropriately.

This is a companion change to constructive-db#800, which adds a rate_limits_module with IP-based rate limiting and moves login throttle configuration to a dedicated settings table.

Updates since last revision

  • Renamed IP_RATE_LIMITEDTOO_MANY_REQUESTS — more generic error code that doesn't leak the rate limiting mechanism (aligns with HTTP 429 semantics). Updated in both this PR and constructive-db#800.

New error codes by category:

Category Codes
CSRF CSRF_TOKEN_REQUIRED, INVALID_CSRF_TOKEN
Rate limiting TOO_MANY_REQUESTS, PASSWORD_RESET_LOCKED_EXCEED_ATTEMPTS
TOTP TOTP_NOT_ENABLED
Account/resource ops NULL_VALUES_DISALLOWED, OBJECT_NOT_FOUND, LIMIT_REACHED, REQUIRES_ONE_OWNER

Review & Testing Checklist for Human

  • Verify TOO_MANY_REQUESTS exactly matches the RAISE in constructive-db#800 — the rename from IP_RATE_LIMITED was done in both repos; confirm the strings are identical (grep for raise_exception('TOO_MANY_REQUESTS') in ast_plpgsql_helpers/procedures/statements.sql).
  • Confirm no sensitive/internal error codes were added — every code in this list is visible to end users. Review that none leak implementation details.
  • Check for any missing codes — review the rate_limits_module generators in constructive-db#800 for any RAISE statements whose codes are not yet in this allowlist.

Notes

  • The existing error codes were not modified; this is purely additive.
  • The codes are organized with inline comments by category to match the existing style in the file.
  • Cross-repo dependency: This PR and constructive-db#800 should be merged together — the DB raises TOO_MANY_REQUESTS and this PR ensures it passes through to clients instead of being masked.

Link to Devin session: https://app.devin.ai/sessions/9034e6efc9bb45b8999b0269a5cd8231
Requested by: @pyramation

Add error codes that are raised by constructive-db deployed functions but
were missing from the production error masking allowlist:

- IP_RATE_LIMITED (new — from rate_limits_module IP throttling)
- PASSWORD_RESET_LOCKED_EXCEED_ATTEMPTS (password reset lockout)
- CSRF_TOKEN_REQUIRED, INVALID_CSRF_TOKEN (CSRF validation)
- TOTP_NOT_ENABLED (TOTP verification)
- NULL_VALUES_DISALLOWED (reset_password validation)
- OBJECT_NOT_FOUND (invite/object lookups)
- LIMIT_REACHED (membership/invite limits)
- REQUIRES_ONE_OWNER (ownership constraints)

Without these, production clients would receive masked 'INTERNAL_SERVER_ERROR'
instead of the actionable error codes.
@devin-ai-integration
Copy link
Copy Markdown
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@pyramation pyramation merged commit 97ea77b into main Apr 16, 2026
49 checks passed
@pyramation pyramation deleted the devin/1776247185-safe-error-codes branch April 16, 2026 04:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant